﻿using System.Windows.Forms;

namespace Main.Substructure
{
    /// <summary>
    /// This class contains easily usable methods to make commonly used methods easy to use.
    /// </summary>
    public static class Utilities
    {
        private static object syncMsgObject = new object(); // Object used to prevent cross-threading.

        /// <summary>Creates a Windows.Forms.MessageBox and displays text to the user.</summary>
        /// <param name="msg">The message to display to the user.</param>
        public static void Message(object msg)
        {
            lock (syncMsgObject)
                MessageBox.Show(msg.ToString());
        }

        /// <summary>Creates a Windows.Forms.MessageBox and displays text to the user.</summary>
        /// <param name="msg">The message to display to the user.</param>
        /// <param name="caption">The title/caption of the MessageBox.</param>
        public static void Message(object msg, object caption)
        {
            lock (syncMsgObject)
                MessageBox.Show(msg.ToString(), caption.ToString());
        }

        /// <summary>Creates a Windows.Forms.MessageBox and displays text to the user.</summary>
        /// <param name="msg">The message to display to the user.</param>
        /// <param name="caption">The title/caption of the MessageBox.</param>
        /// <param name="mbb">Buttons that the user may click.</param>
        public static DialogResult Message(object msg, object caption, MessageBoxButtons mbb)
        {
            lock (syncMsgObject)
            {
                DialogResult result = MessageBox.Show(msg.ToString(), caption.ToString(), mbb);
                return result;
            }
        }

        /// <summary>Creates a Windows.Forms.MessageBox and displays text to the user.</summary>
        /// <param name="msg">The message to display to the user.</param>
        /// <param name="caption">The title/caption of the MessageBox.</param>
        /// <param name="mbb">Buttons that the user may click.</param>
        /// <param name="mbi">The icon the MessageBox displays.</param>
        public static DialogResult Message(object msg, object caption, MessageBoxButtons mbb, MessageBoxIcon mbi)
        {
            lock (syncMsgObject)
            {
                DialogResult result = MessageBox.Show(msg.ToString(), caption.ToString(), mbb, mbi);
                return result;
            }
        }

        /// <summary>Takes a Windows.Form as a parameter and invokes its Show method.</summary>
        /// <param name="form">The Form the user wishes to display.</param>
        public static void LaunchMenu(Form form)
        {
            form.Show();
        }
    }
}
